package chat.client.statemachine.chat;

import chat.VectorClock;
import chat.statemachine.AbstractContent;

/**
 * This class defines the content of a chat message.
 * 
 * @author Denis Conan
 *
 */
public class ChatMessageContent extends AbstractContent implements Cloneable {
	private static final long serialVersionUID = -1359674495084706282L;
	private int sender;
	private String content;
	
	/* Vector clock of this message */
	private VectorClock vectorClock;
	
	public ChatMessageContent(final int s, final String msg, final VectorClock v) {
		sender = s;
		content = msg;
		vectorClock = v;
	}

	public int getSender() {
		return sender;
	}

	public String getContent() {
		return content;
	}
	
	public VectorClock getVectorClock() {
		return vectorClock;
	}
	
	public String toString() {
		return "sender / content = " + sender + " / " + content;
	}
	
	public Object clone() {
		ChatMessageContent cmc = null;
		try {
	    	// On récupère l'instance à renvoyer par l'appel de la 
	      	// méthode super.clone()
	      	cmc = (ChatMessageContent) super.clone();
	    } catch(CloneNotSupportedException e) {
	      	// Ne devrait jamais arriver car nous implémentons 
	      	// l'interface Cloneable
	      	e.printStackTrace(System.err);
	    }
	    cmc.vectorClock = (VectorClock) this.vectorClock.clone();
	    return cmc;
	}
}
